package GUI.Lisenting;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class D02 {
    public static void main(String[] args) {
        Frame frame = new Frame("开始-停止");
        //这里是按钮的默认值
        Button button1 = new Button("Start");
        Button button2 = new Button("Pause");
        //这里是显示定于按钮的“值”
        button2.setActionCommand("button2-Pause");
        button1.setActionCommand("button1-Start");
        MyMonitor myMonitor = new MyMonitor();

        button1.addActionListener(myMonitor);
        button2.addActionListener(myMonitor);

        frame.add(button1,BorderLayout.NORTH);
        frame.add(button2,BorderLayout.SOUTH);
        frame.pack();
        frame.setVisible(true);

    }
}
class MyMonitor implements ActionListener{
    @Override
    public void actionPerformed(ActionEvent e) {
        //e.getActionCommand() 获得按钮的信息的功能
        System.out.println("按钮被点击了:"+e.getActionCommand());
        /*实现公用(一个监听器解决多个按钮的功能)
        * if(e.getActionCommand().equal(A))
        * {                              }
        * else if(e.getActionCommand().equal(B))
        * {                              }
        * */
    }
}
